#define __ASM__ 1
#include "../include/arch/boot/multiboot.h"

#define MB_FLAGS    (MULTIBOOT_MEMORY_INFO | MULTIBOOT_PAGE_ALIGN)
#define p_size      10*4096

.section .multiboot
    .long MULTIBOOT_MAGIC
    .long MB_FLAGS
    .long CHECKSUM(MB_FLAGS)

.section .bss
    .align 16
    tmp_stack_bottom:
        .skip 4096, 0
    tmp_stack_top:

.section .ptd
    .global ptd
    ptd:
        .skip p_size, 0
    ptd_end:

.section .hhk_init_text
    .global _start
_start:
    cli

    movl $tmp_stack_top, %esp

    subl $16, %esp

    /* 为hhk_init调用传递参数 */
    movl $p_size, 4(%esp)
    movl $(ptd - 0xC0000000), (%esp)    /* PTD物理地址 */
    call hhk_init

    /* 加载PTD基地址（物理地址） */
    movl $(ptd - 0xC0000000), %eax
    movl %eax, %cr3

    /* 开启分页与地址转换 (CR0.PG=1, PG.WP=1) */
    movl %cr0, %eax
    orl $0x80010000, %eax
    movl %eax, %cr0

    addl $16, %esp

    /* 进入高半核 */
    pushl $hhk_entry
    ret
.end
